
#include "stm32f10x.h" //stm32头文件
#include "usart.h"
#include "sys.h"
#include "delay.h"
#include "laser_def.h"
#include "vl53l1x.h"
#include "vl53l1x_i2c.h"

uint16_t Distance_data[2] = {0,0};
extern VL53L1_Dev_t VL53L1_dev[];	//2, device param, include I2C
extern uint8_t Ajusted[];//2, adjusted sign, 0-not, 1-had
extern VL53L1_RangingMeasurementData_t VL53L1_data[];//2, ranging result struct, distance, max distance,etc.
extern uint16_t Distance_data[];//2, the catched distance. VL53L1_data->RangeMilliMeter; 
/******************************************************************************/
//void VL53l1_GPIO_Init(void);

int main()
{
	uint8_t mode = 0;
	uint8_t Status = 0;
//	uint8_t data = 0;
	//VL53L1_dev[0].I2cDevAddr=0x52;
	//VL53L1_dev[1].I2cDevAddr=0x54;
	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//分组2
	uart_init(9600);
	delay_init();
	//VL53l1_GPIO_Init();
	//VL53L1_I2C_Init();
	
	Status = VL53L1_init(&VL53L1_dev[0]);
	if(0 != Status)
	{
		printf("VL53L1 Init error!\r\n");
	}
	else
	{
		printf("VL53L1 Init OK\r\n");
	}
	
	if(VL53L1_set_mode(&VL53L1_dev[0],mode))
	{
		printf("mode set error\r\n");
	}
	else
	{
		printf("set mode OK\r\n");
	}
	while(1)
	{
		/*VL53L1_RdByte(&VL53L1_dev[0],0x010f,&data);
		printf("data = 0x%x\r\n",data);
		VL53L1_RdByte(&VL53L1_dev[0],0x0110,&data);
		printf("data = 0x%x\r\n",data);*/
		Status = VL53L1_single_test(&VL53L1_dev[0],&VL53L1_data[0]);
		if(Status==VL53L1_Error_NONE)
		{
			//Distance_data[0]=VL53L1_data[0].RangeMilliMeter;
			printf("Distance = %4d\r\n",Distance);
		}
		else
		{
			printf("measure error\r\n");
		}
		delay_ms(100);
	}
//	return 0;

}
/***************************************************************************/
/***************************************************************************/


